package ee.rumba.iPhoneShop.artwork;


import java.io.IOException;
import java.io.File;

public class Main {
  public static void printUsage() {
    System.out.println("Usage: java -jar iPhoneShop.jar ARTWORK artworkFile export|import targetDir");
    System.out.println("   KeyboardArtwrokMGR v. 0.3 (iiton)");
    System.exit(1);
  }
  public static void main(String[] args) throws IOException {
    if (args.length < 3) {
      printUsage();
    }
    File awFile = new File(args[0]);
    String command = args[1].toUpperCase();
    File targetDir = new File(args[2]);

    if (!awFile.canRead()) {
      System.out.println("Unable to read artwork file " + awFile.getAbsolutePath());
      printUsage();
    }
    if (!targetDir.exists() || !targetDir.canWrite()) {
      System.out.println("Unable to write to targetDir " + targetDir.getAbsolutePath());
      printUsage();
    }
    Artwork aw = new Artwork(awFile);
    if (command.startsWith("EXP")) {
      aw.extractItems(targetDir);
    } else if (command.startsWith("IMP")) {
      aw.importItems(targetDir);
    } else {
      printUsage();
    }
  }
}
